// 验证两次密码是否一致
function checkPassword() {
    let password = document.getElementById("password").value;
    let rePassword = document.getElementById("rePassword").value;
    if (password != rePassword){
        document.getElementById("checkPasswordTip").innerHTML = "两次密码输入不一致，请重新输入！";
        document.getElementById("checkPasswordTip").style.color = "red";
    }else {
        document.getElementById("checkPasswordTip").innerHTML = "密码一致！";
        document.getElementById("checkPasswordTip").style.color = "green";
    }
}

// 注册
function register() {
    let userCode =  $("#userCode").val()
    let password = $("#password").val();
    let data = {
        userCode:userCode,
        password: password,
    };
    if (userCode == null || userCode == "") {
        $("#userCodeTip").text("账号不能为空");
    } else if (password == null || password == "") {
        $("#userCodeTip").text();
        $("#passwordTip").text("密码不能为空");
    } else {
        let result = myJson("/u/login/register", data);
        console.log(result);
        if (result.data.data == "success") {
            window.location.href = "/html/login.html";
            } else if (result.data.data == "repeat"){
            $("#userCodeTip").text("账号已存在");
        }
    }
}

// 点击取消事件
function back() {
    window.location.href = "/html/login.html";
}